package com.auxiliary;

import com.myidis.entity.SignalThreshold;
import java.util.ArrayList;



public class SignalLampCalculator {
	/// <summary>
    /// 构造函数
    /// </summary>
    public SignalLampCalculator()
    {
    }
    /// <summary>
    /// 将输入序列按照阀值映射为灯号：红灯，蓝灯，绿灯，浅蓝灯，黄灯
    /// </summary>
    /// <param name="values">输入序列</param>
    /// <param name="threshold">阀值</param>
    /// <returns></returns>
    private ArrayList<Double> ComputeSingleIndex(ArrayList<Double> values, SignalThreshold threshold) {
        if (values == null || threshold == null) return null;//added by shangwei to avoid expception @20071017

        ArrayList<Double> index = new ArrayList<Double>();

        for (int i = 0; i < values.size(); i++)
        {
            if (values.get(i) >= threshold.getRedValue())
            {
                index.add(SignalLampTimeSequence.RED_VALUE); //单指标落入红灯过热区间
            }
            else if (values.get(i) >= threshold.getYellowValue())
            {
                index.add(SignalLampTimeSequence.YELLOW_VALUE); //单指标落入黄灯趋热区间	
            }
            else if (values.get(i) >= threshold.getGreenValue())
            {
                index.add(SignalLampTimeSequence.GREEN_VALUE);  //单指标落入绿灯正常区间
            }
            else if (values.get(i) >= threshold.getBlueValue())
            {
                index.add(SignalLampTimeSequence.BLUE_VALUE);//单指标落入浅蓝灯趋冷区间
            }
            else
            {
                index.add(SignalLampTimeSequence.LIGNTBLUE_VALUE);  //单指标落入蓝灯过冷区间
            }
        }
        return index;
    }
   /// <summary>
    /// 将指标值按照阀值映射为灯号：红灯，蓝灯，绿灯，浅蓝灯，黄灯
   /// </summary>
   /// <param name="ts">指标数值，即Indicator.TimeSequence</param>
   /// <param name="threshold">阀值</param>
   /// <returns></returns>
    public SignalLampTimeSequence Calculate(TimeSequence ts, SignalThreshold threshold){
        SignalLampTimeSequence signalTS = new SignalLampTimeSequence();
        signalTS.SetTimeSequenceValue(ts.getDateList(), ComputeSingleIndex(ts.getValueList(), threshold));
        return signalTS;
    }
}
